# -*- coding: utf8 -*-

__author__ = "Sergey Dryabzhinsky"

__doc__ = """
Обработка векторов

@author: Sergey Dryabzhinsky
"""

def compare_vectors( v1, v2, min_diff=0, correction=0, parts=100):
    n_eq = 0
    for key in range(parts):
        p1 = v1[key]
        p2 = v2[key]
        p = max((p1, p2,))
        if not p:
            n_eq += 1
        # If difference less then minimal - equal
        elif abs(p1 - p2 + correction) / float(p) <= min_diff:
            n_eq += 1

    return n_eq

def diff_vectors( v1, v2, correction=0, parts=100):
    diff = range(parts)
    for key in range(parts):
        p1 = v1[key]
        p2 = v2[key]
        p = max((p1, p2,))
        if not p:
            diff[key] = 0
        else:
            diff[key] = abs(p1 - p2 + correction) / float(p)

    return diff
